Imports System.Data

Partial Class WebControls_ClientSearch
    Inherits System.Web.UI.UserControl

#Region "Class Variables/Declarations"
    Dim strClientCd As String = ""
    Dim mClientType As eClient_Type

    Public strLastName As String = ""
    Public strFirstName As String = ""
    Public strMiddleName As String = ""
    Public strAdd1 As String = ""
    Public strAdd2 As String = ""
    Public dtBday As Date
    Public strCountry As String = ""
    Public strCity As String = ""
    Public strGender As String = ""

    Public Event Policy_Selected()

    Enum eClient_Type
        Client = 1
        Beneficiary = 2
        Trustee = 3
    End Enum
#End Region

#Region "Class Properties"
    Public Property Client_Cd() As String
        Get
            Client_Cd = strClientCd
        End Get
        Set(ByVal value As String)
            strClientCd = value
        End Set
    End Property

    Public Property Client_Type() As eClient_Type
        Get
            Client_Type = mClientType
        End Get
        Set(ByVal value As eClient_Type)
            mClientType = value
        End Set
    End Property
#End Region

#Region "Class Functions"
    Public Sub doSearch()

        Dim vo As New DAOMain.VW_RPT_BIRTHDAY_LIST_VO
        Dim cf As New CIMSfunc

        With vo
            .CLIENTNAME = "%" & Trim(txtName.Text) & "%"
            If Trim(txtAge.Text) <> "" Then .AGE = txtAge.Text

            DataGrid.CurrentPageIndex = 0
            ViewState.Add("VO", vo)
            Call BindGrid(vo)
        End With

        cf = Nothing
        vo = Nothing
    End Sub

    Private Sub BindGrid(ByVal vo As DAOMain.VW_RPT_BIRTHDAY_LIST_VO)
        Dim dao As New DAOMain.VW_RPT_BIRTHDAY_LIST_DAO
        Dim dt As DataTable = dao.Search(vo, , True)

        DataGrid.DataSource = dt
        DataGrid.DataBind()

        dt = Nothing
        dao = Nothing
    End Sub
#End Region

#Region "Control Events"
    Protected Sub Search_btn_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Search_btn.Click
        Call doSearch()
    End Sub

    Protected Sub DataGrid_PageIndexChanged(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridPageChangedEventArgs) Handles DataGrid.PageIndexChanged
        DataGrid.CurrentPageIndex = e.NewPageIndex

        Call BindGrid(ViewState("VO"))
    End Sub

    Protected Sub DataGrid_ItemCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles DataGrid.ItemCommand
        If e.CommandName = "Select_Client" Then
            Dim dt As DataTable
            Dim strClientCd = e.Item.Cells(1).Text

            Select Case Trim(e.Item.Cells(2).Text)
                Case "Client"
                    mClientType = eClient_Type.Client

                    Dim dao As New DAOMain.POLICY_CLIENT_DTL_DAO_MAIN
                    Dim vo As New DAOMain.POLICY_CLIENT_DTL_VO_MAIN

                    vo.POLICY_CLIENT_CD = strClientCd
                    dt = dao.Search(vo)

                    If dt.Rows.Count > 0 Then
                        strLastName = dt.Rows(0)("POLICY_CLIENT_LAST_NAME")
                        strFirstName = dt.Rows(0)("POLICY_CLIENT_FIRST_NAME")
                        strMiddleName = dt.Rows(0)("POLICY_CLIENT_MIDDLE_NAME")
                        strAdd1 = dt.Rows(0)("POLICY_CLIENT_ADDRESS")
                        strAdd2 = dt.Rows(0)("POLICY_CLIENT_ADDRESS2")
                        dtBday = dt.Rows(0)("BIRTHDAY")
                        strCountry = dt.Rows(0)("COUNTRY_CD")
                        strCity = dt.Rows(0)("CITY_CD")
                        strGender = dt.Rows(0)("GENDER")
                    End If

                    dao = Nothing
                    vo = Nothing
                Case "Beneficiary"
                    mClientType = eClient_Type.Beneficiary

                    Dim dao As New DAOMain.POLICY_BENE_DTL_DAO
                    Dim vo As New DAOMain.POLICY_BENE_DTL_VO

                    vo.POLICY_BENE_CD = strClientCd
                    dt = dao.Search(vo)

                    If dt.Rows.Count > 0 Then
                        strLastName = dt.Rows(0)("POLICY_BENE_LAST_NAME")
                        strFirstName = dt.Rows(0)("POLICY_BENE_FIRST_NAME")
                        strMiddleName = dt.Rows(0)("POLICY_BENE_MIDDLE_NAME")
                        strAdd1 = dt.Rows(0)("POLICY_BENE_ADDRESS")
                        strAdd2 = dt.Rows(0)("POLICY_BENE_ADDRESS2")
                        dtBday = dt.Rows(0)("BIRTHDAY")
                        strCountry = dt.Rows(0)("COUNTRY_CD")
                        strCity = dt.Rows(0)("CITY_CD")
                        strGender = dt.Rows(0)("GENDER")
                    End If

                    dao = Nothing
                    vo = Nothing
                Case "Trustee"
                    mClientType = eClient_Type.Trustee

                    Dim dao As New DAOMain.POLICY_TRUSTEES_DTL_DAO
                    Dim vo As New DAOMain.POLICY_TRUSTEES_DTL_VO

                    vo.POLICY_TRUSTEES_CD = strClientCd
                    dt = dao.Search(vo)

                    If dt.Rows.Count > 0 Then
                        strLastName = dt.Rows(0)("POLICY_TRUSTEES_LAST_NAME")
                        strFirstName = dt.Rows(0)("POLICY_TRUSTEES_FIRST_NAME")
                        strMiddleName = dt.Rows(0)("POLICY_TRUSTEES_MIDDLE_NAME")
                        strAdd1 = dt.Rows(0)("POLICY_TRUSTEES_ADDRESS")
                        strAdd2 = dt.Rows(0)("POLICY_TRUSTEES_ADDRESS2")
                        dtBday = dt.Rows(0)("BIRTHDAY")
                        strCountry = dt.Rows(0)("COUNTRY_CD")
                        strCity = dt.Rows(0)("CITY_CD")
                        strGender = dt.Rows(0)("GENDER")
                    End If

                    dao = Nothing
                    vo = Nothing
            End Select

            RaiseEvent Policy_Selected()
        End If
    End Sub

#End Region

End Class
